package mblog.core.api;

/**
 * Created by zhangyue on 16/4/10.
 */
public class WebRestResponse<D> {

        private D data;

        private int code; // 处理状态：0: 成功 其他表示失败

        private String message;

        private WebRestResponse() {
        }

        private WebRestResponse(D data) {
            this.data = data;
        }

        /**
         * 创建成功响应
         *
         * @return 响应
         */
        public static WebRestResponse createWebRestResponse() {
            return new WebRestResponse();
        }

        /**
         * 创建包含数据的响应
         *
         * @param data 数据
         * @param <D>  类型
         * @return 响应
         */
        public static <D> WebRestResponse createWebRestResponse(D data) {
            return new WebRestResponse(data);
        }

        /**
         * 创建异常响应
         *
         * @param exception 响应状态
         * @return 响应
         */
        public static WebRestResponse createWebRestResponse(UnCheckedException exception) {
            WebRestResponse restResponse = new WebRestResponse();
            if (null != exception) {
                restResponse.setCode(exception.getCode());
                restResponse.setMessage(exception.getMessage());
            }
            return restResponse;
        }


    public D getData() {
        return data;
    }

    public void setData(D data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
